
// koa_session_simple.js

const Koa = require('koa');
const session = require('koa-session');
const app = new Koa();

// Error: .keys required for signed cookies
app.keys = ['welcome session simple'];

const myLogic = ctx => {
    // ignore favicon
    if (ctx.path === '/favicon.ico') return;

    let n = ctx.session.views || 0;
    ctx.session.views = ++n;
    ctx.body = n + ' views';
};

app.use(session(app));
app.use(myLogic);

app.listen(3000);
console.log('listening on port 3000');

